package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    //查看购物车是否有已经相同数据
    ShoppingCart select(ShoppingCart shoppingCart);

    //更新购物车同种商品的数量
   @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateData(ShoppingCart select);

   //添加购物车数据
   @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor,number, amount, create_time) VALUES (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

   //查看购物车
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    //清空购物车
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void cleanShoppingCart(Long userId);

    //删除购物车中的一个商品
    void substract(ShoppingCart shoppingCart);

}
